              package com.java.diagnostics.visualizer.displayer.html;
              
              import com.java.diagnostics.visualizer.coredisplayers.util.Messages;
              import com.java.diagnostics.visualizer.data.AggregateData;
              import com.java.diagnostics.visualizer.data.DataSet;
              import com.java.diagnostics.visualizer.data.TupleData;
              import com.java.diagnostics.visualizer.data.axes.Axis;
              import com.java.diagnostics.visualizer.data.axes.DataAxis;
              import com.java.diagnostics.visualizer.data.axes.YDataAxis;
              import com.java.diagnostics.visualizer.data.ids.ID;
              import com.java.diagnostics.visualizer.metadata.TupleMetaData;
              import com.java.diagnostics.visualizer.metadata.TupleMetaData.TableField;
              import com.java.diagnostics.visualizer.properties.OutputProperties;
              import java.io.BufferedWriter;
              import java.io.File;
              import java.io.IOException;
              import java.text.MessageFormat;
              
              public class ArithmeticTableTupleDataWriter extends TupleDataWriter
              {
                private static final String MAXIMUM = Messages.getString("HTMLReportDisplayer.maximum");
              
                private static final String MEAN = Messages.getString("HTMLReportDisplayer.mean");
              
                private static final String MINIMUM = Messages.getString("HTMLReportDisplayer.minimum");
              
                private static final String TOTAL = Messages.getString("HTMLReportDisplayer.total");
              
                protected ArithmeticTableTupleDataWriter(DataSet dataSet, OutputProperties outputProperties, AggregateData representativeData, BufferedWriter buffer, ID id, File directory)
                {
                  super(dataSet, outputProperties, representativeData, buffer, id, 
                    directory);
                }
              
                protected void writeColumnHeadings() throws IOException
                {
                  this.buffer.write(NEWLINE);
                  openRow();
                  if (this.dataSet.getVariants().length > 1) {
                    addTableHeader(VARIANT, 2);
                  }
              
                  TupleMetaData metaData = this.representativeData.getTupleData(this.id)
                    .getTupleMetaData();
              
                  if (metaData != null) {
                    for (TupleMetaData.TableField field : metaData.getTableFields()) {
                      switch (field) {
                      case MIN:
                        addTableHeader(MEAN, 1);
                        break;
                      case MEAN:
                        addTableHeader(MINIMUM, 1);
                        break;
                      case MAX:
                        addTableHeader(MAXIMUM, 1);
                        break;
                      case TOTAL:
                        addTableHeader(TOTAL, 1);
                      }
              
                    }
              
                    closeRow();
                    openRow();
                    String unitHeading;
                    //String unitHeading;
                    if (this.axis.getAxis().getType() == 1) {
                      unitHeading = this.axis.getLabel();
                    } else {
                      String units = this.outputProperties.getUnits(this.axis.getAxis());
                      unitHeading = MessageFormat.format("{0} ({1})", new Object[] { 
                        this.axis.getLabel(), units });
                    }
                    for (int i = 0; i < metaData.getTableFields().length; i++) {
                      addTableHeader(unitHeading, 1);
                    }
                  }
                  closeRow();
                  this.oddRow = false;
                }
              
                protected void addRow(TupleData data)
                  throws IOException
                {
                  if (data != null) {
                    String yUnits = this.outputProperties.getYUnits(data);
                    TupleMetaData metaData = data.getTupleMetaData();
                    if (metaData != null) {
                      this.buffer.write(NEWLINE);
                      for (TupleMetaData.TableField field : metaData.getTableFields()) {
                        switch (field) {
                        case MIN:
                          addTableCell(data.getYAxis()
                            .formatUnconverted(data.getMeanY(yUnits), yUnits));
                          break;
                        case MEAN:
                          addTableCell(data.getYAxis()
                            .formatUnconverted(data.getMinY(yUnits), yUnits));
                          break;
                        case MAX:
                          addTableCell(data.getYAxis()
                            .formatUnconverted(data.getMaxY(yUnits), yUnits));
                          break;
                        case TOTAL:
                          addTableCell(data.getYAxis()
                            .formatUnconverted(data.getTotalY(yUnits), yUnits));
                        }
              
                      }
              
                      this.buffer.write(NEWLINE);
                    }
                  }
                  else {
                    this.buffer.write(NEWLINE);
                    TupleMetaData metaData = this.representativeData.getTupleData(this.id)
                      .getTupleMetaData();
                    if (metaData != null) {
                      for (int i = 0; i < metaData.getTableFields().length; i++) {
                        addTableCell("&nbsp;");
                      }
              
                    }
              
                    this.buffer.write(NEWLINE);
                  }
                }
              }

